package com.netty.test.server;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;

public class MyEncoder extends ChannelOutboundHandlerAdapter {
    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
    	byte[] m = (byte[]) msg;
    	
        ByteBuf encoded = ctx.alloc().buffer(m.length);
        encoded.writeBytes(m);
        ctx.write(encoded, promise); // (1)
    }
}